//
//  GQHCommentView.m
//  Xanthium
//
//  Created by GuanQinghao on 05/03/2018.
//  Copyright © 2018 GuanQinghao. All rights reserved.
//

#import "GQHCommentView.h"
#import "GQHHeader.h"


@interface GQHCommentView () <UITextViewDelegate>

@end


@implementation GQHCommentView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        
        [self loadLocalData];
        [self loadUserInterface];
    }
    return self;
}

#pragma mark --Data
- (void)loadLocalData {
    
    
}

#pragma mark --View
- (void)loadUserInterface {
    
    UIScrollView *bottomScrollView = [[UIScrollView alloc] init];
    bottomScrollView.backgroundColor = kWhiteColor;
    [self addSubview:bottomScrollView];
    [bottomScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self).with.offset(self.qh_statusBarHeight + self.qh_navigationBarHeight);
        make.left.and.right.and.bottom.mas_equalTo(self);
    }];
    
    _qh_avatarImageView = [[UIImageView alloc] init];
    _qh_avatarImageView.layer.cornerRadius = 5.0f;
    _qh_avatarImageView.layer.masksToBounds = YES;
    [bottomScrollView addSubview:_qh_avatarImageView];
    [_qh_avatarImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(10);
        make.left.mas_equalTo(GQH_MARGIN_SINGLE);
        make.size.mas_equalTo(CGSizeMake(60.0, 60.0));
    }];
    
    _qh_nameLabel = [[UILabel alloc] init];
    _qh_nameLabel.font = kDefaultFont;
    _qh_nameLabel.textAlignment = NSTextAlignmentLeft;
    [bottomScrollView addSubview:_qh_nameLabel];
    [_qh_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(_qh_avatarImageView);
        make.left.mas_equalTo(_qh_avatarImageView.mas_right).with.offset(10);
        make.right.mas_equalTo(bottomScrollView).with.offset(GQH_MARGIN_SINGLE);
        make.height.mas_equalTo(20);
    }];
    
    _qh_subtitleLabel = [[UILabel alloc] init];
    _qh_subtitleLabel.font = kSmallerFont;
    _qh_subtitleLabel.textAlignment = NSTextAlignmentLeft;
    [bottomScrollView addSubview:_qh_subtitleLabel];
    [_qh_subtitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(_qh_nameLabel.mas_bottom);
        make.left.and.right.and.height.mas_equalTo(_qh_nameLabel);
    }];
    
    _qh_contentLabel = [[UILabel alloc] init];
    _qh_contentLabel.font = kSmallerFont;
    _qh_contentLabel.textAlignment = NSTextAlignmentLeft;
    [bottomScrollView addSubview:_qh_contentLabel];
    [_qh_contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(_qh_subtitleLabel.mas_bottom);
        make.left.and.right.and.height.mas_equalTo(_qh_subtitleLabel);
    }];
    
    UIView *separatorView = [[UIView alloc] init];
    separatorView.backgroundColor = kLightGrayColor;
    [bottomScrollView addSubview:separatorView];
    [separatorView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(_qh_avatarImageView.mas_bottom).with.offset(10);
        make.left.and.right.mas_equalTo(self).with.inset(GQH_MARGIN_SINGLE);
        make.height.mas_equalTo(1);
    }];
    
    UILabel *titleLabel = [[UILabel alloc] init];
    titleLabel.text = @"本次评价";
    titleLabel.font = kDefaultFont;
    titleLabel.textAlignment = NSTextAlignmentLeft;
    [bottomScrollView addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(separatorView.mas_bottom).with.offset(10);
        make.left.mas_equalTo(GQH_MARGIN_SINGLE);
        make.width.mas_equalTo(80);
        make.height.mas_equalTo(30);
    }];
    
    UIView *scoreView = [[UIView alloc] init];
    scoreView.backgroundColor = kWhiteColor;
    [bottomScrollView addSubview:scoreView];
    [scoreView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(titleLabel);
        make.left.mas_equalTo(titleLabel.mas_right);
        make.width.mas_equalTo(150);
        make.height.mas_equalTo(30);
    }];
    
    _qh_scoreView = [[QHRatingView alloc] initWithFrame:CGRectMake(0, 0, 150, 30)];
    _qh_scoreView.backgroundColor = kWhiteColor;
    [scoreView addSubview:_qh_scoreView];
    
    UILabel *scoreLabel = [[UILabel alloc] init];
    scoreLabel.textAlignment = NSTextAlignmentLeft;
    [bottomScrollView addSubview:scoreLabel];
    [scoreLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(titleLabel);
        make.left.mas_equalTo(_qh_scoreView.mas_right).with.offset(10);
        make.right.mas_equalTo(bottomScrollView).with.offset(GQH_MARGIN_SINGLE);
        make.height.mas_equalTo(30);
    }];
    
    UIView *separatorView1 = [[UIView alloc] init];
    separatorView1.backgroundColor = kLightGrayColor;
    [bottomScrollView addSubview:separatorView1];
    [separatorView1 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(titleLabel.mas_bottom).with.offset(10);
        make.left.and.right.mas_equalTo(bottomScrollView).with.inset(GQH_MARGIN_SINGLE);
        make.height.mas_equalTo(1);
    }];
    
    UILabel *titleLabel1 = [[UILabel alloc] init];
    titleLabel1.text = @"评价内容";
    titleLabel1.textAlignment = NSTextAlignmentLeft;
    [bottomScrollView addSubview:titleLabel1];
    [titleLabel1 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(separatorView1).with.offset(10);
        make.left.mas_equalTo(GQH_MARGIN_SINGLE);
        make.width.mas_equalTo(100);
        make.height.mas_equalTo(30);
    }];
    
    _qh_textView = [[UITextView alloc] init];
    _qh_textView.backgroundColor = kWhiteColor;
    _qh_textView.layer.borderWidth = 0.5;
    _qh_textView.layer.borderColor = kLightGrayColor.CGColor;
    _qh_textView.layer.cornerRadius = 5;
    _qh_textView.layer.masksToBounds = YES;
    _qh_textView.delegate = self;
    [bottomScrollView addSubview:_qh_textView];
    [_qh_textView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(titleLabel1.mas_bottom).with.offset(10);
        make.left.and.right.mas_equalTo(self).with.inset(GQH_MARGIN_SINGLE);
        make.height.mas_equalTo(60);
    }];
}

#pragma mark --Delegate
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    
    // 全局统一收起键盘
    [[[UIApplication sharedApplication] keyWindow] endEditing:YES];
}

@end
